package com.xiaoke.security.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @Author 小柯
 * @Date 2019/11/2  18:56
 **/
@Component
@Slf4j
public class MyUserDetailsService implements UserDetailsService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    //注入mapper


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("登录用户" + username);
        String encode = passwordEncoder.encode("123456");
        log.info("加密后的密码" + encode);

        //根据用户名查找用户信息  用户名、密码、授权(从数据库拿出来)
        /*return new User(username, encode, AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));*/
        return new User(username, encode,true,true,true,true, AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
